package org.graduates.webapp.actions.course.json;

import java.util.ArrayList;
import java.util.List;

import org.apache.struts2.convention.annotation.Action;
import org.apache.struts2.convention.annotation.Result;
import org.graduates.webapp.actions.BaseAction;
import org.projects.graduates.domain.ContentStatus;
import org.projects.graduates.domain.HomeworkAssignments;
import org.projects.graduates.domain.HomeworkHandin;
import org.projects.graduates.domain.TimeTable;

/**
 * 得到某个课程内容的所有作业
 * 
 * @author Administrator
 * 
 */
@Action(results = { @Result(name = "input", type = "json"),
		@Result(name = "success", type = "json") })
public class GetHomeworksAction extends BaseAction {

	private static final long serialVersionUID = -1206109836390133520L;

	// 某个课程内容的ID
	private long tid = 0L;

	private List<HomeworkHandin> handins = new ArrayList<HomeworkHandin>();
	
	private HomeworkAssignments ha;

	private boolean success = false;

	public String execute() {

		if (0L == tid) {
			return SUCCESS;
		}

		TimeTable tt = TimeTable.get(TimeTable.class, tid);

		if (null == tt) {
			return SUCCESS;
		}

		ha = HomeworkAssignments.findby(tt);

		if (null == ha) {
			return SUCCESS;
		}
		this.handins.addAll(gradApplication.handinsOfHomework(
				pagerOf(HomeworkHandin.class, " where o.homework.id=" + ha.getId()), ha, ContentStatus.ARTWORK,
				this.getRepository()));
		
		success = true;
		return SUCCESS;
	}

	public HomeworkAssignments getHa() {
		return ha;
	}

	public long getTid() {
		return tid;
	}

	public void setTid(long tid) {
		this.tid = tid;
	}

	public List<HomeworkHandin> getHandins() {
		return handins;
	}

	public boolean isSuccess() {
		return success;
	}


}
